package com.kfm.base.io.c;

import java.io.*;

public class Demo02 {

    public static void main(String[] args) {
        // FileReader fr = new FileReader("d:/io/buffered-reader.txt"); 等价
        try(InputStreamReader isr = new InputStreamReader(new FileInputStream("d:/io/buffered-reader.txt"));
            BufferedReader br = new BufferedReader(isr);
        ){
//            char[] chars = new char[4];
//            int size;
//
//            while( (size = br.read(chars)) != -1){
//                System.out.print(new String(chars, 0, size));
//            }

            // 借助缓冲区，实现了按行读取 readLine()
//            String str; // 读取到的内容汇总不包含换行符
//            while ((str = br.readLine()) != null){
//                System.out.print(str);
//            }

            // 读取单个字符
            int c;
            while( (c = br.read()) != -1){ // 死循环
                if ((char)c == '，'){
                    br.mark(1);
                }
                System.out.print((char) c);

                if ((char)c == '。'){
                    br.reset(); // 重置
                }
            }

            System.out.println("读取完毕");

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
